import { _decorator, Component, Node } from 'cc';
import { Battle } from './Battle';
import { Globals } from './Globals';
import { Player } from './Player/Player';
const { ccclass, property } = _decorator;

@ccclass('Shield')
export class Shield extends Component {
    // 持续时间
    duration = 3;

    protected onEnable(): void {
        // 护盾免伤
        Battle.playerNode.getComponent(Player).isShield = true;
    }
    protected onDisable(): void {
        // 恢复正常伤害
        Battle.playerNode.getComponent(Player).isShield = false;
    }

    start() {

    }

    update(deltaTime: number) {
        if (Battle.playerNode) {
            this.node.setWorldPosition(Battle.playerNode.getWorldPosition());
        }
        // 持续时间减少
        this.duration -= deltaTime;
        if (this.duration <= 0) {

            Globals.putNode(this.node);
        }
    }
}


